
import React, {Component} from 'react';
import { ScrollView, Text, View, Image, 
  TouchableOpacity,StatusBar
} from 'react-native';
import styles from './index.style.js'
import TopView from './TopView'
import SplitView from '@/components/SplitView'
import Cell from '@/components/Cell'
import {jumpPage} from '@/util/common'
import DeviceStorage from '@/util/DeviceStorage'
import { setUserData } from '@/actions/user'
export default class Mine extends Component{
  static navigationOptions = ({ navigation }) =>{
    return{
      //title:'个人中心',
      header: null
    }
  };
  constructor(props){
    super(props)
    this.state = ({
      yue: 120.00
    })
  }
  componentDidMount = async() => {
    //const value = await DeviceStorage.get('user')
    //console.log('mine user',value)
    //console.log('props', this.props)
    // this.props.subscribe(()=>{
    //   console.log('***',this.props.user)
    // });
  }
  _addMoney(){
    this.setState({
      yue: 220.00
    })
  }
  _cellPress(type){
    let page
    if(type == -3) page = "financeBill"
    if(type == -2) page = "myBuy"
    if(type == 0) page = "myRecomm"
    if(type == 1) page = 'userInfo'
    if(type == 2) page = 'addressManage'
    if(type == 3) page = 'myBuy'
    if(type == 4) page = "help"
    jumpPage(this.props.navigation,page)
  }
  _test(){
    //alert(2)
    let newUser = this.props.user
    newUser.avatar = 'https://ss3.bdstatic.com/70cFv8Sh_Q1YnxGkpoWK1HF6hhy/it/u=4285611627,3487298056&fm=26&gp=0.jpg'
    newUser.nickname = '嗯嗯3'
   // DeviceStorage.save('user',JSON.stringify(newUser))
    //console.log('top view props',this.props)
    //this.props.dispatch(setUserData(user))
    this.props.dispatch(setUserData(newUser))
    // this.props.dispatch({
    //   type: 'UPDATE_USER',
    //   user: newUser
    // })
  }
  render(){
    return(
      <ScrollView style={styles.container} showsVerticalScrollIndicator={false}>
        {/* <StatusBar translucent={true}/> */}
        <TopView press={()=>this._test()} {...this.props} userInfo={this.props.user}/>

        <SplitView height={5}/>

        <SplitView height={5}/>
        <Cell title="个人信息" press={()=>this._cellPress(1)}/>
        <Cell title="地址管理" press={()=>this._cellPress(2)}/>
        <Cell title="我的订单" />
        <Cell title="新手帮助"  press={()=>this._cellPress(4)}/>
        <Cell title="认筹排行" style={{borderBottomWidth:0}}/>
        <SplitView height={10}/>
      </ScrollView>
    )
  }
}